package org.japo.java.swing.igu;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.HeadlessException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import org.japo.java.swing.listeners.GEA;
import org.japo.java.swing.listeners.GET;

public class IGU extends JFrame {

    //Declarar campos necesarios
    private JLabel lblUser;
    private JLabel lblPass;
    private JTextField txfUser;
    private JPasswordField psfPass;
    private JButton btnAceptar;
    private JButton btnCancelar;

    public IGU() throws HeadlessException {

        iniciarComponentes();

    }

    private void iniciarComponentes() {
        JPanel pnlPrincipal = new JPanel();

        //Dimension de los campos
        Dimension dimLabel = new Dimension(80, 30);
        Dimension dimCampos = new Dimension(120, 30);
        Dimension dimBotones = new Dimension(100, 30);

        //Instaciar la fuente que vamos a utilizar
        Font f = new Font("Calibri", Font.BOLD + Font.ITALIC, 16);

        //Gestor de eventos de accion
        GEA gea = new GEA(this);

        //Gestor de eventos de teclado
//        GET get = new GET(this);
        //Etiqueta USUARIO
        lblUser = new JLabel();
        lblUser.setFont(f);
        lblUser.setText("Usuario");
        lblUser.setPreferredSize(dimLabel);
        lblUser.setHorizontalAlignment(JLabel.RIGHT);
        lblUser.setLocation(10, 10);
        pnlPrincipal.add(lblUser);

        //Campo de texto  USUARIO
        txfUser = new JTextField();
        txfUser.setFont(f);
        txfUser.setText("");
        txfUser.setPreferredSize(dimCampos);
        txfUser.setHorizontalAlignment(JLabel.RIGHT);
        txfUser.setLocation(120, 10);
        txfUser.addActionListener(gea);
        pnlPrincipal.add(txfUser);

        //Etiqueta CONTRASEÑA
        lblPass = new JLabel();
        lblPass.setFont(f);
        lblPass.setText("Contraseña");
        lblPass.setPreferredSize(dimLabel);
        lblPass.setLocation(5, 45);
//        lblPass.setHorizontalAlignment(JLabel.RIGHT);
        pnlPrincipal.add(lblPass);

        //Campo de texto  CONTRASEÑA
        psfPass = new JPasswordField();
        psfPass.setFont(f);
        psfPass.setText("");
        psfPass.setPreferredSize(dimCampos);
        psfPass.setHorizontalAlignment(JLabel.RIGHT);
        psfPass.setLocation(120, 45);
        psfPass.addActionListener(gea);
        pnlPrincipal.add(psfPass);

        //Boton Aceptar
        btnAceptar = new JButton();
        btnAceptar.setFont(f);
        btnAceptar.setText("Aceptar");
        btnAceptar.setHorizontalAlignment(JLabel.CENTER);
        btnAceptar.setPreferredSize(dimBotones);
        btnAceptar.setLocation(10, 80);
        pnlPrincipal.add(btnAceptar);
//        btnAceptar.addKeyListener(get);

        //Boton Cancelar
        btnCancelar = new JButton();
        btnCancelar.setFont(f);
        btnCancelar.setText("Cancelar");
        btnCancelar.setHorizontalAlignment(JLabel.CENTER);
        btnCancelar.setPreferredSize(dimBotones);
        btnCancelar.setLocation(100, 80);
        pnlPrincipal.add(btnCancelar);
//        btnCancelar.addKeyListener(get);

        // Ventana principal
        setContentPane(pnlPrincipal);
        setTitle("Login prueba");
        setResizable(false);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(290, 150);
        setLocationRelativeTo(null);
//        pack();

    }

}
